class TreeNode():
    def __init__(self,val=0,left=None,right=None):
        self.val=val 
        self.left=left 
        self.right=right

from collections import deque
def build_level(lst):
    root=TreeNode(lst[0])
    que=deque([root])
    i=1 
    while len(que)>0 and i<len(lst):
        cur=que.popleft()
        if lst[i]: 
            cur.left=TreeNode(lst[i])
            que.append(cur.left)
        if i+1<len(lst) and lst[i+1]:
            cur.right=TreeNode(lst[i+1])
            que.append(cur.right)
        i+=2 
    return root 



def diameterOfBinaryTree(root):
    def traversel(root):
        nonlocal ans
        if not root: return 0
        l_len=traversel(root.left)
        r_len=traversel(root.right)
        ans=max(ans,l_len+r_len)
        return max(l_len,r_len)+1
    ans=0
    traversel(root)
    return ans

root=build_level([1,2,3,4,5,None,None])
print(diameterOfBinaryTree(root))